<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <link type="text/css" rel="stylesheet" th:href="@{/css/all.css}"/>
    <link type="text/css" rel="stylesheet" th:href="@{/plugin/zTree_v3-master/css/metroStyle/metroStyle.css}"/>
    <link type="text/css" rel="stylesheet" th:href="@{/plugin/bootstrap-datetimepicker/bootstrap-datetimepicker.min.css}"/>
<!--
    <script language="JavaScript" th:src="@{/js/all.js}" src="js/all.js"></script>
-->

    <script language='JavaScript' th:src='@{/plugin/jQuery/jQuery-2.2.0.min.js}'></script>
    <script language='JavaScript' th:src="@{/ajax/layer/layer.min.js}"></script>
    <script language='javascript' th:src='@{/js/constant.js}'></script>
    <script language='JavaScript' th:src='@{/plugin/jQuery/jquery.mousewheel.min.js}'></script>
    <script language='JavaScript' th:src='@{/plugin/jquery-easyui-1.5.1/jquery.easyui.min.js}'></script>
    <script language='JavaScript' th:src='@{/plugin/bootstrap/js/bootstrap.min.js}'></script>
    <script language='JavaScript' th:src='@{/plugin/bootstrap-table/bootstrap-table.js}'></script>
    <script language='JavaScript' th:src='@{/plugin/adminLTE/js/app.min.js}'></script>
    <script language='JavaScript' th:src='@{/plugin/lobibox/dist/js/lobibox.js}'></script>
    <script language='JavaScript' th:src='@{/js/network.js}'></script>
    <script language='JavaScript' th:src='@{/js/common.js}'></script>
    <script language='JavaScript' th:src='@{/js/public.js}'></script>
    <script language='JavaScript' th:src='@{/plugin/bootstrap-datetimepicker/js/moment-with-locales.min.js}'></script>
    <script language='JavaScript' th:src='@{/plugin/iCheck/icheck.min.js}'></script>
    <script language='JavaScript' th:src='@{/plugin/zTree_v3-master/js/jquery.ztree.core.min.js}'></script>
    <script language='JavaScript' th:src='@{/plugin/zTree_v3-master/js/jquery.ztree.excheck.min.js}'></script>
    <script language='JavaScript' th:src='@{/plugin/bootstrap-datetimepicker/bootstrap-datetimepicker.min.js}'></script>

    <style type="text/css">
        .form-group{
            margin-top: 5px;
            margin-bottom: 5px;
        }
        #user-role-table td {
           border-left-width: 0px !important;
            border-right-width: 0px !important;
         }

        #user-role-table th {
            border-left-width: 0px !important;
            border-right-width: 0px !important;
        }
        .dataMessageTop{
            height: 40px;
            text-align: center;
            line-height:40px;
        }
        .dataMessage{
            height: 30px;
            text-align: center;
            line-height:30px;
        }
        .dataMessageKey{
            width: 50%;
            height:100%;
            float: left;
            background-color: #efeeed;
            border: 1px solid darkgray;
        }
        .dataMessageValue{
            width: 50%;
            height:100%;
            float: left;
            background-color: #f3e7d4;
            border: 1px solid darkgray;

        }

    </style>
</head>
<body class="body-contrainner fadeInUp">
<input type="text" id="userName" th:value="${userName}" hidden />
<div class="box box-info">
    <div class="box-header with-border">
        <form id="form-search" class="form-inline has-info">
            <div class="form-group">
                <label class="control-label">导出名称</label>
                <input type="text" name="export_name@@like" class="form-control" placeholder="请输入导出名称">
            </div>
            <div class="form-group">
                <label class="control-label">创建人</label>
                <input type="text" name="creator@@like" class="form-control" placeholder="请输入创建人名称">
            </div>
            <div class="form-group">
                <label class="control-label">备注</label>
                <input type="text" name="mark@@like" class="form-control" placeholder="请输入备注">
            </div>
        </form>
        <div class="box-tools pull-right">
            <button type="button" class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i></button>
        </div>
    </div>
    <div class="box-body" style="padding-top: 0px;">
        <div id="tool-bar">
            <button id="btn-search" type="button" class="btn btn-info"><i class="fa fa-search margin-r-5"></i>查询</button>
            <button id="btn-add" type="button" class="btn btn-default"><i class="fa fa-plus margin-r-5"></i>新增</button>
            <button id="btn-edt" type="button" class="btn btn-default"><i class="fa fa-edit margin-r-5"></i>编辑</button>
            <button id="btn-del" type="button" class="btn btn-default"><i class="fa fa-remove margin-r-5"></i>删除</button>
            <button id="btn-view" type="button" class="btn btn-default"><i class="fa fa-eye margin-r-5"></i>数据视图</button>
            <button id="btn-export" type="button" class="btn btn-default"><i class="fa fa-download margin-r-5"></i>导出</button>
        </div>
        <table id="data-table" class="table table-bordered" data-striped="true" data-pagination="true" data-search="false"
               data-search-on-enter-key="true" data-show-columns="true" data-show-refresh="true"
               data-show-toggle="true" 	data-show-pagination-switch="true" data-id-field="id"
               data-unique-id="id" data-click-to-select="true" data-side-Pagination="server"
               data-cache="false" data-method="get" data-toolbar="#tool-bar" data-query-params="getParam">
            <thead>
            <tr id="tab">

            </tr>
            </thead>
        </table>
    </div>
</div>



<div id="input-modal" class="modal fade">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
                <h4 class="modal-title text-info">填写数据源信息</h4>
            </div>
            <div class="modal-body">

                <form id="form-input" class="form-horizontal has-info form-validate">
                    <div class="form-group">
                        <label class="control-label col-md-2 required1">导出名称</label>
                        <div class="col-md-9">
                            <input type="text" class="form-control" name="export_name" placeholder="请输入导出名称" >
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="control-label col-md-2 required1">数据SQL</label>
                        <div class="col-md-9">
<!--
                            <input type="text" class="form-control" name="export_sql" placeholder="请输入数据SQL" >
-->
                            <textarea class="form-control" rows="10" name="export_sql" placeholder="请输入数据SQL"></textarea>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="control-label col-md-2 required1">备注</label>
                        <div class="col-md-9">
                            <input type="text" class="form-control" name="mark" placeholder="请输入备注" >
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button id="btn-cancel" type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                <button id="btn-save" type="button" class="btn btn-info">保存</button>
            </div>
        </div>
    </div>
</div>





<div id="input-modal1" class="modal fade">
    <div class="modal-dialog">
        <div class="modal-content" style="min-width: 1000px;margin-left:-200px;" >
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
                <center><span  style="font-size:20px;">导出模板选择</span></center>
            </div>

            <div class="modal-body">
                <table id="data-table1" class="table table-bordered"
                       data-method="get" data-side-Pagination="server" data-pagination="true"
                       data-striped="true" data-id-field="id" data-unique-id="id" data-click-to-select="true"
                       data-search="false"  data-cache="false"  data-query-params="getParam1">
                    <thead>
                    <tr id='tab1'>
                    </tr>
                    </thead>
                </table>
            </div>
            <div class="modal-footer">
                <button id="btn-cancel1" type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                <button id="btn-save1" type="button" class="btn btn-info">保存</button>
            </div>
        </div>
    </div>
</div>


<form id="form-search1" class="form-inline has-info" style="display: none">
    <div class="form-group">
        <label class="control-label">模板名称</label>
        <input type="text" id="file_name" name="file_name@@like" class="form-control" placeholder="请输入模板名称">
    </div>
    <div class="form-group">
        <label class="control-label">模板备注</label>
        <input type="text" id="mark" name="mark@@like" class="form-control" placeholder="请输入模板备注">
    </div>
    <div class="form-group">
        <label class="control-label">模板类型</label>
        <input type="text" id="file_end_name" name="file_end_name@@eql" class="form-control" placeholder="请输入模板类型">
    </div>
    <div class="form-group">
        <label class="control-label">上传者</label>
        <input type="text" id="creater" name="creater@@eql" class="form-control" placeholder="请输入上传者">
    </div>
</form>




<div id="input-modal2" class="modal fade">
    <div class="modal-dialog">
        <div class="modal-content" style="min-width: 600px;margin-left:-200px;" >
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
                <center><span  style="font-size:20px;">数据信息展示</span></center>
            </div>

            <div class="modal-body" id="messageBody" style="height:340px; overflow:scroll;">

            </div>
            <div class="modal-footer">
              <center>  <button id="btn-cancel2" type="button" class="btn btn-default" data-dismiss="modal">关闭</button></center>
            </div>
        </div>
    </div>
</div>








<script language="JavaScript">
   ajax.postData(publicData.urls.system.getFields, {'tableName':'sys_my_export'}, function (data) {
       var html='<th data-field="state" data-checkBox="true" >#</th>';
       html+='<th data-field="rowNum" data-align="left" data-halign="left" data-valign="middle" data-formatter="bootstrapFormatter.rowNumFormatter">序号</th>'

       for(var i = 0;i < data.length;++i){
           var codeAndInfo = data[i];
           if(codeAndInfo.column_name == "id"){

           }else{
               html+='<th data-field="'+codeAndInfo.column_name+'" data-align="left" data-halign="left"'
                   +'data-valign="middle" data-sortable="true">'+codeAndInfo.column_comment+'</th>';
           }
       }
       $("#tab").html(html);
       if ( data!=null||data!="") {
           $("#data-table").bootstrapTable("refresh");
           $("#data-table").bootstrapTable({url: publicData.urls.system.getPage});
       }else{
           $("#tab").html("不存在");
       }
   });
   //这个携带页面查询参数
    function getParam(params) {
        var total=commonTools.getBootstrapParams(params, $("#form-search"))
        total.params.tableName='sys_my_export';
        return total;
    }

    $("#btn-search").click(function () {
        $("#data-table").bootstrapTable("refresh");
    });

    $("#btn-add").click(function () {
        commonTools.setFormData({}, $("#form-input"));
        $("#input-modal").attr("data-save-type", "add");
        $("#input-modal").modal("show");
    });

    $("#btn-edt").click(function () {
        var datas = $("#data-table").bootstrapTable("getSelections");
        if (datas.length == 0) {
            messageBox.info("请选择要修改的数据");
            return;
        }
        if (datas.length > 1) {
            messageBox.info("只能同时修改一条数据");
            return;
        }
        commonTools.setFormData(datas[0], $("#form-input"));
        $("#input-modal").attr("data-save-type", "edt");
        $("#input-modal").modal("show");
    });



   $("#btn-save").click(function () {
       var datas = $("#data-table").bootstrapTable("getSelections");
        var saveType = $("#input-modal").attr("data-save-type");
        var saveData = $("#form-input").serializeObject();
       var column=new Array();
       var value=new Array();
       var i=0;
       for (var demo in saveData) {
           column[i]=demo;
           value[i]=saveData[demo];
           i++;
       }
       var message={}
       var mydate = new Date();
       var dateNow=mydate.toLocaleString();
       message.tableName="sys_my_export";


       if(saveType=='edt'){
           message.id=datas[0].id;
       }else{
           column.push("creator")
           column.push("create_time")
           value.push($("#userName").val())
           value.push(dateNow)
       }
       message.column=column;
       message.value=value;
       message.saveType=saveType;
       ajax.postData(publicData.urls.system.addOrEdt,{'message':JSON.stringify(message)}, function (data) {
                $("#input-modal").modal("hide");
                if (saveType == "add") {
                    messageBox.success("添加成功");
                }else {
                    messageBox.success("保存成功");
                }
                $("#data-table").bootstrapTable("refresh");
            });
    });

    $("#btn-del").click(function () {
        var datas = $("#data-table").bootstrapTable("getSelections");
        if (datas.length == 0) {
            messageBox.info("请选择要删除的数据");
            return;
        }
        var ids="";
        for(var i=0;i<datas.length;i++){
            ids+=datas[i].id
            if(i==datas.length-1){

            }else{
                ids+=",";
            }
        }


        messageBox.confirm("您确认要删除该数据吗？", function(){
            ajax.postData(publicData.urls.system.del, {"id": ids,"tableName":"sys_my_export"}, function () {
                messageBox.success("删除成功");
                $("#data-table").bootstrapTable("refresh");
            });
        }, undefined);
    });

//=====================模板选择框
   ajax.postData(publicData.urls.system.getFields, {'tableName':'sys_upload_modal'}, function (data) {
       var html='<th data-field="state" data-radio="true"  data-toggle="a">#</th>';
       html+='<th data-field="rowNum" data-align="left" data-halign="left" data-valign="middle" data-formatter="bootstrapFormatter.rowNumFormatter">序号</th>'

       for(var i = 0;i < data.length;++i){
           var codeAndInfo = data[i];
           if(codeAndInfo.column_name == "id"||codeAndInfo.column_name == "uuid_file_name"){

           }else{
               html+='<th data-field="'+codeAndInfo.column_name+'" data-align="left" data-halign="left"'
                   +'data-valign="middle" data-sortable="true">'+codeAndInfo.column_comment+'</th>';
           }
       }
       $("#tab1").html(html);
       if ( data!=null||data!="") {
           $("#data-table1").bootstrapTable("refresh");
           $("#data-table1").bootstrapTable({url: publicData.urls.system.getPage});
       }else{
           $("#tab1").html("不存在");
       }
   });

   //这个携带页面查询参数
   function getParam1(params) {
       var total=commonTools.getBootstrapParams(params, $("#form-search1"))
       total.params.tableName='sys_upload_modal';
       if(total.sort==undefined){
           total.sort='create_time';
           total.order='desc';
       }
       return total;
   }

   $("#btn-export").click(function () {
       var datas = $("#data-table").bootstrapTable("getSelections");
       if (datas.length == 0) {
           messageBox.info("请选择要导出的数据源");
           return;
       }
       $("#data-table1").bootstrapTable("refresh");
       $("#input-modal1").modal("show");
   });

   $("#btn-save1").click(function () {
       var datas = $("#data-table").bootstrapTable("getSelections");
       var datas1 = $("#data-table1").bootstrapTable("getSelections");
       if (datas1.length == 0) {
           messageBox.info("请选择导出的模板");
           return;
       }
       var sqls=new Array();
       for (var i=0;i<datas.length;i++) {
           sqls[i]=datas[i].export_sql;
       }
       var message={}
       message.sqls=sqls;

       var sql="";
       for (var j=0;j<datas.length;j++) {
           sql+=datas[j].export_sql;
           if(j==datas.length-1){

           }else{
               sql+=" union ";
           }
       }

       ajax.postData(publicData.urls.resource.dataVeiw,{'message':JSON.stringify(message)}, function (data) {
           if(typeof(data) == 'string'){
               messageBox.error(data);
           }else {
               ajax.postData(publicData.urls.resource.downloadCheck,{"uFileName":datas1[0].uuid_file_name}, function (data) {
                   if(data==""){
                       window.location.href=publicData.urls.resource.myExport+"?uFileName="+datas1[0].uuid_file_name+"&sqls="+sql+"&fileName="+datas1[0].file_name;
                       $("#input-modal1").modal("hide");
                       messageBox.success("保存成功");
                   }else{
                       messageBox.error(data);
                   }
               });
           }
       });
   });
//============查看数据源

   $("#btn-view").click(function () {
       var datas = $("#data-table").bootstrapTable("getSelections");
       if (datas.length == 0) {
           messageBox.info("请选择数据源");
           return;
       }
       var sqls=new Array();
       for (var i=0;i<datas.length;i++) {
           sqls[i]=datas[i].export_sql;
       }
       var message={}
       message.sqls=sqls;
      ajax.postData(publicData.urls.resource.dataVeiw,{'message':JSON.stringify(message)}, function (data) {
          if(typeof(data) == 'string'){
              messageBox.error(data);
          }else {
              var html='<div class="dataMessageTop"><div class="dataMessageKey" >数据key值</div><div class="dataMessageValue">数据value值</div></div>';
              for(var i=0;i<data.length;i++){
                  var htmlStr='<div class="dataMessage"><div class="dataMessageKey">'+data[i].keyValue+'</div><div class="dataMessageValue">'+data[i].Value+'</div></div>'
                  html+=htmlStr;
              }
              $("#messageBody").html(html);
              $("#input-modal2").modal("show");
          }
       });
   });









</script>
</body>
</html>